<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>我的电商系统</title>
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/bootstrap-theme.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/fornt.css">
</head>
<body id="shopcart">
<div class="container"> 
	<div class="row">
		<div class="col-md-3 nav-left">
			<a href="<?php echo site_url();?>"><img id="logo"  src="<?php echo base_url();?>public/img/logo.jpg" /></a>
		</div>
		<div class="col-md-9"><img style="height:50px;margin-top:20px" class="pull-right" src="<?php echo base_url();?>public/img/shop_step_2.jpg" /></div>
		
	</div>
</div>
<br>
<div class="container">
	<div class="row">
		<div class="col-md-12">
			<h4>收货地址：<button id="addAddress" class="btn btn-success btn-sm pull-right">添加地址</button></h4>
			<br />
			<form action="" method="post">
			<table class="table table-bordered" >
			<?php foreach($address as $d){?>
				<tr>
					<td width="40px"><input type="radio" name="address_id" value="<?=$d->id?>" /></td>
					<td>收件人：<?php echo $d->name;?></td>
					<td>地址：<?php echo $d->address;?></td>
					<td>手机号：<?php echo $d->phone;?></td>
					<td class="text-center" width="200"><a href="#">修改</a> &nbsp;<a href="#"><i class="glyphicon glyphicon-minus-sign" style="color:red"></i></a></td>
				</tr>
			<?php }?>
			</table>
			<br>
			<table cellpadding="0" cellspacing="0" class="shopcart_table">
				<tr class="shopcart_table_item">
					<th class="item">商品</th>
					<th class="price">单价</th>
					<th class="num">数量</th>
					<th class="sum" >小计(元)</th>
				</tr>
				<?php 
					$sum=0;
					foreach($data as $usercart){
					$p=$this->Product_model->get_one_product($usercart['product_id']);
				?>
				<tr class="tr">
				<input type="hidden" name="product_id[]" value="<?php echo $p->id;?>" />
				<input type="hidden" name="num[]" value="<?php echo $usercart['num'];?>" />
					<td>
						<img src="<?php echo base_url().$p->img?>" class="pull-left" />
						<p><a class="title" href="<?php echo site_url('Product/detail/'.$p->id)?>"><?php echo $p->title;?></a></p>
					</td>
					<td class="price">￥<span><?php echo $p->price;?></span></td>
					<td class="cart">
						<?php echo $usercart['num']?>
					</td>
					<td width="120px" class="sum">¥<span ><?php echo $p=intval($p->price) * intval($usercart['num']);?></span></td>
				</tr>
				<?php $sum=$sum+$p; }?>
			</table>
			<br>
			<button type="submit" class="btn btn-danger pull-right">提交订单</button>
		</form>
		</div>
	</div>
</div>
<div class="modal fade" id="addAddressForm">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">添加收货地址</h4>
      </div>
      <div class="modal-body">
      		<div class="form-group">
			    <label>收件人</label>
			    <input id="name" type="text" class="form-control" placeholder="请输入姓名..." >
		  	</div>
		  	<div class="form-group">
			    <label>收货地址</label>
			    <textarea id="address" style="width:100%"　class="form-control" placeholder="请输入收货地址..."></textarea> 
		  	</div>
		  	<div class="form-group">
			    <label>手机号</label>
			    <input id="phone" type="text" class="form-control" placeholder="请输入手机号...">
		  	</div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button id="addressSave" type="button" class="btn btn-primary">保存</button>
      </div>
    </div>
  </div>
</div>
</body>
	<script type="text/javascript" src="<?php echo base_url();?>public/js/jquery.js"></script>
	<script type="text/javascript" src="<?php echo base_url();?>public/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#addAddress').click(function(){
				$('#addAddressForm').modal('show')
			})
			$('#addressSave').click(function(){
				var name=$('#name').val();
				var address=$('#address').val();
				var phone=$('#phone').val();
				$.post("<?php echo site_url('shopping/add_one_ADDress')?>",{
					'name':name,
					'address':address,
					'phone':phone,
				},function(data){
					if(data=='ok'){
						location.reload();
					}
				})
				return false;
			})
		})
	</script>
</html>